home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / src / presto / scheduler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-02  |  2.5 KB  |  108 lines

  1.  
  2. //
  3. // Scheduler object where all the grungy details
  4. // are kept.
  5. //
  6.  
  7.  
  8.  
  9.  
  10.  
  11. //
  12. // All ops on base ThreadPool are "does-not-understand"
  13. //
  14. class ThreadPool    {
  15. public:
  16.     ThreadPool();
  17.     virtual ~ThreadPool();
  18.     virtual Thread*    get();
  19.     virtual void    insert(Thread*);
  20.     virtual int    size();
  21.     int        empty()
  22.         { return size() == 0; }
  23. };
  24.  
  25.  
  26.  
  27. //
  28. // Derive public to allow coersion
  29. //
  30. class ThreadPoolQueue : public ThreadPool    {    
  31.     ThreadQ    *tp_tq;
  32. public:
  33.     ThreadPoolQueue();
  34.     ~ThreadPoolQueue();
  35.     Thread    *get();
  36.     void    insert(Thread*);
  37.     int    size();
  38. };
  39.  
  40.  
  41.  
  42.  
  43. class Processor;
  44. struct sigcontext;
  45.  
  46. #define DEFQUANTUM    0        /* milliseconds */
  47.  
  48. class Scheduler  : public Object    {
  49. protected:
  50.         ThreadPool*     sc_t_ready [NUMPROCS];  // threads wanting to run
  51.     Process*    sc_p_procs[NUMPROCS];    // workers live here
  52.     int        sc_p_numschedulers;    // max# which can be active
  53.     int        sc_p_activeschedulers;    // # which are active
  54.     int        sc_p_busybits;        // 32 is the proc limit
  55.     Spinlock    *sc_lock;        // Lock busybits
  56.     inline int      busybits(int on);    // atomic set
  57.     int        sc_quantum;        // in ms. if 0, no preemption
  58. public:
  59.     Scheduler(int nschedulers, int quantum = DEFQUANTUM);
  60.     virtual ~Scheduler();
  61.     virtual Thread* getreadythread();    
  62.     virtual void resume(Thread* t);        // put t back on ready q
  63.     virtual int invoke();            // yeah yeah yeah...
  64.     void begin(Thread* t)            // start t running somewhere
  65.         { resume(t); }
  66.     virtual void halt();            // come to a crashing stop! nicely
  67.     virtual void abort(int sigself);      // not so nicely (may core dump)
  68. //    virtual void kill(Thread* t);            // nuke t
  69.     virtual void    error(char *s);        
  70.     virtual void    print(ostream& = cout);
  71.     int    readyqlen()
  72.         { return sc_t_ready[thisproc->id()]->size(); }
  73.     int    quantum()
  74.         { return sc_quantum; }
  75.     int    pidtoprocnum(int p);
  76.     void    storecore(int pnum);        // rename a core file
  77.     virtual ThreadPool*    getreadypool();
  78.     virtual ThreadPool*    setreadypool(ThreadPool*);// use new, return old
  79.     virtual void initsighandlers(int setupdefaults);
  80. friend    sigpreempt_alrm(int sig, int code, sigcontext *scp);
  81. friend  schedulerSigHandler(int sig, int code, sigcontext *scp);
  82. friend  schedulerReapChild(int sig, int code, sigcontext *scp);
  83. };
  84.  
  85.  
  86. //
  87. // Keep track of who's busy and who's not.  Access routine must do
  88. // the locking.
  89. //
  90. inline int
  91. Scheduler::busybits(int on)
  92. {
  93.     register int procmask = 1<<(thisproc->id());
  94.     register int shadowbits;
  95.     
  96. //    sc_lock->lock();    
  97.     if (on)
  98.         shadowbits = sc_p_busybits |= procmask;
  99.     else
  100.         shadowbits = sc_p_busybits &= ~procmask;
  101. //    sc_lock->unlock();        
  102.     return shadowbits;
  103. }
  104.  
  105. extern Scheduler    *sched;
  106.  
  107.  
  108.